cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-07 LANGUAGES CXX)

find_package(OpenMP REQUIRED)
find_package(Eigen3 3.3 REQUIRED CONFIG)

if (TARGET Eigen3::Eigen)
    message(STATUS "FOUND Eigen3 v${EIGEN3_VERSION_STRING} in ${EIGEN3_INCLUDE_DIR}")
endif ()

add_executable(linear-algebra linear-algebra.cpp)

find_package(BLAS)                          # blas 接口是 fortran 速度很快
if (BLAS_FOUND)
    message(STATUS "Eigen will use some subroutines from BLAS.")
    message(STATUS "See: http://eigen.tuxfamily.org/doxdevel/TopicUsingBlasLapack.html")
    target_compile_definitions(linear-algebra PRIVATE EIGEN_USE_BLAS)
    target_link_libraries(linear-algebra PUBLIC ${BLAS_LIBRARIES})
else()
    message(STATUS "BLAS not found. Using Eigen own functions")
endif()

target_link_libraries(linear-algebra PUBLIC Eigen3::Eigen OpenMP::OpenMP_CXX)